$().ready(function() {
    getSupplierByUpdate(null);
    getMaterialByUpdate(null);
	validateRule();

});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});



//$('#signupForm').serialize(),// 你的formid
function save() {
	// setReportImg();
	var formData = new FormData($("#signupForm")[0]);
    console.log($('#signupForm').serialize())
	$.ajax({
        url : getProjectName()+"/material/purchase/save",
        async: false,
        type: "POST",
        // dataType: "json",
        //  data: formData,
		data : $('#signupForm').serialize(),
        // cache: false,
        // contentType: false,
        // processData: false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
            purchaser : {
				required : true
			},
            purchaseNo : {
            	required : true
			}
		},
		messages : {
            purchaser : {
				required : icon + "请输入采购人姓名"
			},
            purchaseNo : {
                required : icon + "请输入采购批次"
            }
		}
	})
}